<?php

/*

    MMetaverse - Open Metaverse Web Manager

    Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

    http://www.maryjanesoft.com
    http://www.marlonj.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General
    Public License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    Boston, MA  02111-1307  USA

    $Id$

*/

Yii::import('application.components.thunderz.TPortlet');
Yii::import('application.models.mmetaverse.MMetaverseModel');

/**
 * Show grid status information
 */
class MGridStatusPortlet extends TPortlet {

    /**
     * Metaverse
     *
     * @var MMetaverse
     */
    private $metaverse;
    
    /**
     * Create a new Portlet 
     */
    public function MGridStatusPortlet() {
        // Set title and get OpenSim 
        $this->title = 'GridStatus';
        $this->metaverse = MMetaverseModel::getMetaverse();
    }

    /**
     * Returns the numbers of users in the grid
     *
     * @return integer Number of users 
     */
    protected function getNumUsers() {
        try {
            $userManager = $this->metaverse->getUserManager();
            return $userManager->getNumberOfUsers();
        } catch (Exception $e) {
        }
        // If problems return 0
        return 0;
    }

    /**
     * Returns the numbers of regions in the grid
     *
     * @return integer Number of regions
     */
    protected function getNumRegions() {
        try {
            $regionManager = $this->metaverse->getRegionManager();
            return $regionManager->getNumberOfRegions();
        } catch (Exception $e) {
        }
        // If problems return 0
        return 0;
    }

    /**
     * Returns the numbers of users online
     *
     * @return integer Number of users online
     */
    protected function getNumberOfAgentsOnline() {
        try {
            $userManager = $this->metaverse->getUserManager();
            return $userManager->getNumberOfAgentsOnline();
        } catch (Exception $e) {
        }
        // If problems return 0
        return 0;
    }

    /**
     * Returns the numbers of logins in the past month 
     *
     * @return integer Number logins in the past month
     */
    protected function getNumberOfLastMonthLogins() {
        try {
            $userManager = $this->metaverse->getUserManager();
            return $userManager->getNumberOfLastMonthLogins();
        } catch (Exception $e) {
        }
        // If problems return 0
        return 0;
    }

    /**
     * Render the content of the portlet
     */
    protected function renderContent() {
        // Use the view
        $this->render('MGridStatusPortletView');
    }
}

?>
